<script>
layui.use('table', function(){
  var table = layui.table;
  
  	table.render({
	    elem: '#test'
	    ,url:'menu/list/'
	    ,toolbar: '#toolbarDemo'
	    ,cellMinWidth: 60 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	    ,cols: [[
	      	{field:'Mid', title: 'ID', sort: true}
	      	,{field:'Name',  title: '菜单名'}
			,{field:'ParentName', title: '父菜单'}
			,{field:'Seq', title: '排序'}
			,{fixed: 'right', width:200, title:'操作', toolbar: '#barDemo'}
	    ]]
		,page:true
  	});

	//头工具栏事件
  	table.on('toolbar(test)', function(obj){
	    switch(obj.event){
		  case 'add':
			layer.open({
				type:2,
				area: ['800px','500px'],
				offset: 'auto',
				title:'添加',
				content:"menu/add"
			});
	      break;
	    };
	});

	//监听行工具事件
  	table.on('tool(test)', function(obj){
	    var data = obj.data;
	    //console.log(obj)
	    if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
			layui.jquery.get("/menu/deletedo?mid="+data.Mid);
	        obj.del();
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
			//self.location="menu/edit?id="+data.Mid;
			layer.open({
				type:2,
				area: ['800px','500px'],
				offset: 'auto',
				title:'编辑',
				content:"menu/edit?mid="+data.Mid+"&name="+data.Name+"&parent="+data.Parent+"&seq="+data.Seq
			});
	    }else if(obj.event === 'editformat'){
			//self.location="format/edit?mid="+data.Mid;
			//layer.open({
			//	type:2,
			//	area: ['900px','600px'],
			//	offset: 'auto',
			//	title:'编辑',
			//	content:"format/edit?mid="+data.Mid
			//});
			window.open("format/edit?mid="+data.Mid)
	    }
	  });
	
});

</script>

